'use strict'

const path = require('path')
const express = require('express')
const webpack = require('webpack')

const config = require('./webpack.config')

const app = express()
const compiler = webpack(config)
const PORT = process.env.PORT || 3344

app.use(require('webpack-dev-middleware')(compiler, {
  noInfo: true,
  // publicPath: config.output.publicPath
}))

app.use(require('webpack-hot-middleware')(compiler))

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'src/index.html'))
})

app.listen(PORT, 'localhost', err => {
  if (err) {
    console.error(err)
    return
  }
  console.log(`Listening at PORT of ${PORT}`)
})